package com.atguigu.srb.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * @program: srb
 * @author: 龙龙
 * @create: 2022-02-19 16:11
 * @description:
 **/
@Component
public class MyFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        //鉴权过滤器
        System.out.println("可以对访问权限进行赚钱");

        MultiValueMap<String, HttpCookie> cookies = exchange.getRequest().getCookies();
        if (null!= cookies && cookies.size() >0 ){
            HttpCookie token = cookies.get("userInfo").get(0);
            String value = token.getValue();
            System.out.println(value);
        }
        HttpHeaders headers = exchange.getRequest().getHeaders();
        if (headers.isEmpty() && null != headers) {
            List<String> list = headers.get("token");
            if (list.size() >0){
                String s = list.get(0);
            }
        }





        return chain.filter(exchange);
    }
}
